using System;
using DecisionesInteligentes.iEvalua.Helpers;
using DecisionesInteligentes.iEvalua.Models;

namespace DecisionesInteligentes.iEvalua.Web.Services
{
	public class SecurityService: ISecurityService
	{
		private readonly Password password;
		
		public SecurityService(Password password)
		{
			this.password = password;
		}
		public User Authenticate(string username, string password, int applicationId)
		{
			return User.FindAllByUsernameAndApplication(username, applicationId);
		}
		
		public string HashPassword(string password)
		{
			byte[] salt = this.password.CreateRandomSalt();
			
			return this.password.ComputeSaltedHash(password, salt);
		}
		
		public bool VerifyPassword(string password, string saltedhashedPassword)
		{
			return this.password.VerifyPassword(password, saltedhashedPassword);
		}
	}
}